package com.baseframe.sys.service.impl;


import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baseframe.sys.entity.FrameUserRole;
import com.baseframe.sys.service.IFrameUserRoleService;
import com.baseframe.sys.service.dao.FrameUserRoleRepository;

/**
 * @author xuxf
 */
@Service("frameUserRoleService")
public class FrameUserRoleServiceImpl implements IFrameUserRoleService {

    @Autowired
    private FrameUserRoleRepository frameUserRoleRepository;
    @PersistenceContext
	private EntityManager em;

	@Override
	public List<FrameUserRole> findAllByUserguid(String userguid) {
		// TODO Auto-generated method stub
		return frameUserRoleRepository.findAllByUserguid(userguid);
	}

	@Override
	public boolean hasRight(String userguid, String roleguid) {
		String hql="select count(1) from FrameUserRole where userguid='"+userguid+"' and roleguid='"+roleguid+"'";
		int total = Integer.parseInt(em.createQuery(hql).getSingleResult().toString());
		if(total>0)
			return true;
		return false;
	}

	/*@Override
	public List<String> queryRoleIdList(String userguid) {
		// TODO Auto-generated method stub
		return frameUserRoleRepository.findRoleguidByUserguid(userguid);
	}*/

}
